package manager.helpers.table;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import manager.auxiliares.Configurations;

public class TableRender
        extends DefaultTableCellRenderer {

    private int selectedRow = -1;

    public TableRender() {
        super();
        selectedRow = -1;
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        try {
            if (row == selectedRow) {
                setForeground(java.awt.Color.WHITE);
                setBackground(Configurations.getSelectedTableRowColor());
            } else if (row % 2 == 0) {
                setForeground(java.awt.Color.BLACK);
                setBackground(Configurations.getEvenTableRowColor());
            } else {
                setForeground(java.awt.Color.BLACK);
                setBackground(Configurations.getOddTableRowColor());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return this;
    }

    public void setSelectedRow(int selectedRow) {
        this.selectedRow = selectedRow;
    }
}
